package com.pow.entity;

import java.util.List;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
@Table(name="roles")
public class Role {


	@Id
	
	private String id;//角色id
	private String name;//角色名称
	private Integer int0;//预留int字段
	private String string0;//预留字符串字段
	@ManyToMany(fetch=FetchType.LAZY) //多对多关系 
	 @JoinTable(name="role_module_tb", //指定第三张中间表名称
	 //本表主键 roleId 与第三张中间表 user_role_tb 的外键 user_role_tb_role_id 对应.本表与中间表的外键对应关系
	 joinColumns={@JoinColumn(name="role_module_tb_role_id")}, //另一张表与中间表的外键的对应关系
	 inverseJoinColumns={@JoinColumn(name="role_module_tb_module_id")})
	@NotFound(action = NotFoundAction.IGNORE) //NotFound : 意思是找不到引用的外键数据时忽略，NotFound 默认是 exception
	
	private List<Module> modules;//
	@ManyToMany(fetch=FetchType.LAZY) //多对多关系 
	 @JoinTable(name="role_permission_tb", //指定第三张中间表名称
	 //本表主键 roleId 与第三张中间表 user_role_tb 的外键 user_role_tb_role_id 对应.本表与中间表的外键对应关系
	 joinColumns={@JoinColumn(name="role_permission_tb_role_id")}, //另一张表与中间表的外键的对应关系
	 inverseJoinColumns={@JoinColumn(name="role_permission_tb_permission_id")})
	@NotFound(action = NotFoundAction.IGNORE) //NotFound : 意思是找不到引用的外键数据时忽略，NotFound 默认是 exception
	
	private List<Permission> permission;//一个角色对应多个权限
	public Role() {
		super();
		// TODO Auto-generated constructor stub
	}
	
	

	

	public List<Permission> getPermission() {
		return permission;
	}





	public void setPermission(List<Permission> permission) {
		this.permission = permission;
	}





	public Role(String id, String name, Integer int0, String string0, List<Module> modules,
			List<Permission> permission) {
		super();
		this.id = id;
		this.name = name;
		this.int0 = int0;
		this.string0 = string0;
		this.modules = modules;
		this.permission = permission;
	}





	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Integer getInt0() {
		return int0;
	}
	public void setInt0(Integer int0) {
		this.int0 = int0;
	}
	public String getString0() {
		return string0;
	}
	public void setString0(String string0) {
		this.string0 = string0;
	}
	public List<Module> getModules() {
		return modules;
	}
	public void setModules(List<Module> modules) {
		this.modules = modules;
	}
	
	@Override
	public String toString() {
		return "Role [id=" + id + ", name=" + name + ", int0=" + int0 + ", string0=" + string0 + ", modules=" + modules
				+ ", permission=" + permission + "]";
	}
	
	
	
	
	
}
